package com.example.change2;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.media.Image;
import android.net.Uri;
import android.os.Bundle;
import android.text.Editable;
import android.text.Layout;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.change2.utils.LogUtils;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView textView;
    private TextView textView2;
    private TextView textView3;
    private TextView button1;
    private Button button2;
    private TextView textView4;
    private LinearLayout Layout1;
//    初始化线性布局
    private EditText editText1;

//    图片
    private ImageView mimage1;
    @SuppressLint("MissingInflatedId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;//hellow
        });

//  -------------------------------------------------------------------------------------
//      图片
        mimage1 = findViewById(R.id.image1);
        mimage1.setImageDrawable(getDrawable(R.mipmap.voleyball));
        mimage1.setImageResource(R.mipmap.voleyball);
        mimage1.setBackground(getDrawable(R.mipmap.voleyball));
        mimage1.setBackgroundResource(R.drawable.button_bg_selector);
        mimage1.setOnClickListener(this);
//  -------------------------------------------------------------------------------------


//        点击文字时候实现的内容
        textView=findViewById(R.id.textView);
        textView2=findViewById(R.id.textView2);
        textView3=findViewById(R.id.textView3);
        textView4=findViewById(R.id.textView4);
//        按钮的注册
        button1=findViewById(R.id.buttom_1);
        button2 = findViewById(R.id.buttom_2);
        Layout1 = findViewById(R.id.main);
//        输入框的注册
        editText1 = findViewById(R.id.edit1);

//  -------------------------------------------------------------------------------------

//        输入框
//        默认输入内容
        editText1.setText("asdfasdf");
//        设置焦点 光标闪烁
        editText1.requestFocus();
//        设置光标位置
        editText1.setSelection(2);
//        监听事件 能够动态的看到输入的状态和内容
        editText1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                LogUtils.d("shuruku","这是输入框的提示,变化之前的状态"+s.toString());
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                LogUtils.d("shuruku","onTextChanged"+s.toString());
            }

            @Override
            public void afterTextChanged(Editable s) {
                LogUtils.d("shuruku","afterTextChanged"+s.toString());
                textView.setText(s.toString());
            }
        });


//-----------------------------------------------------------------
//        第一个按钮
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtils.d("TAG", "====onClick:显示文字 =========");
                shouwToast("按钮的文字--------");
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("http://www.baidu.com"));
                startActivity(intent);
                LogUtils.d("TAG","按钮被点击");
            }
        });
//        -------------------------------------------------------------------------------
//          第二个按钮
        button2.setBackground(getDrawable(R.drawable.button_bg_selector));
//        button2.setBackgroundResource(R.mipmap.dp);
//        字体大小
        button2.setTextSize(getResources().getDimension(R.dimen.text_size));
//        字体颜色
        button2.setTextColor(getColor(R.color.black));

//        button2的点击事件
        button2.setOnClickListener(this);

//  -------------------------------------------------------------------------------------

        Layout1.setOnClickListener(this);

//  -------------------------------------------------------------------------------------
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                跳转到目标
//            Intent intent = new Intent(MainActivity.this,SecondActivety.class);
//            startActivity(intent);
                shouwToast("文字一");
            }
        });
        textView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogUtils.d("TAG", "====onClick:跳转页面 =========");
                shouwToast("文字二");
                onTextView1Click(2);
            }
        });

        textView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                shouwToast("文字三");
            }
        });


//        按钮四
        textView4.setOnClickListener(this);
//        new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                LogUtils.d("TAG","textview4 beidianji");
//            }
//        }
//          向textview添加文字 动态设定
//        textView5.setText("111111111");
//        textView5.setText(R.string.test);
        textView4.setText(getResources().getString(R.string.test));
//        设置消失
//        textView5.setVisibility(View.GONE);
//        textView.setVisibility(View.GONE);

//        invisible 在消失之后不能响应点击事件
//        textView3.setVisibility(View.INVISIBLE);

//         设置背景
//        textView5.setBackground(getDrawable(R.mipmap.dp));
        textView4.setBackgroundResource(R.mipmap.dp);

//        字体大小
//        textView5.setTextSize(12);
        textView4.setTextSize(getResources().getDimension(R.dimen.text_size));

//        字体颜色 int值 接受色值 通过getcolor转换的得到 white是颜色的id
        textView4.setTextColor(getColor(R.color.white));
//  -------------------------------------------------------------------------------------
        LogUtils.d("TAG","-------------------textview5 显示的文字是："+textView4.getText());

    }
    private void onTextView1Click(int i){
        LogUtils.d("TAG", "====shouwToast: 判断是否出现一句话还是跳转页面========="+i);
        if (i == 1){
            shouwToast("TextView 1 Click ");
        } else if (i == 2) {
            showActivity();
        }
    }
    private void  shouwToast(String text){
        LogUtils.d("TAG", "====shouwToast: ========="+text);
        Toast.makeText(this,text,Toast.LENGTH_LONG).show();
    }
    private void showActivity(){
        LogUtils logUtils = new LogUtils();
        logUtils.v();
        LogUtils.d("TAG", "====shouwToast: 跳转页面方法=========");
            Intent intent = new Intent(MainActivity.this,SecondActivety.class);
            startActivity(intent);


    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
//        swith case 报错
        if (id == R.id.buttom_2){
            LogUtils.d("TAG","button 被点击");
        } else if (id == R.id.textView4) {
            LogUtils.d("TAG","textview4 被点击");
        } else if (id == R.id.main) {
            LogUtils.d("TAG","main 被点击");
        } else if (id == R.id.image1) {
            LogUtils.d("TAG","image 被点击");
        }
    }
}